package com.qezhhnjy.mall.coupon.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.coupon.SkuFullReduction;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.coupon.service.SkuFullReductionService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 商品满减信息 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "商品满减信息接口")
@Slf4j
@RequestMapping("/sku-full-reduction")
public class SkuFullReductionController {
    @Resource
    private SkuFullReductionService skuFullReductionService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取商品满减信息信息")
    public BaseResult<SkuFullReduction> get(Long id) {
        SkuFullReduction skuFullReduction = skuFullReductionService.getById(id);
        return BaseResult.success(skuFullReduction);
    }

    @PostMapping("/save")
    @Operation(summary = "新增商品满减信息信息")
    public BaseResult<SkuFullReduction> save(@RequestBody SkuFullReduction skuFullReduction) {
        skuFullReductionService.save(skuFullReduction);
        return BaseResult.success(skuFullReduction);
    }

    @PutMapping("/update")
    @Operation(summary = "更新商品满减信息信息")
    public BaseResult<SkuFullReduction> update(@RequestBody SkuFullReduction skuFullReduction) {
        skuFullReductionService.updateById(skuFullReduction);
        return BaseResult.success(skuFullReduction);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取商品满减信息信息")
    public BaseResult<Page<SkuFullReduction>> page(@RequestBody Page<SkuFullReduction> page) {
        skuFullReductionService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除商品满减信息信息")
    public BaseResult<Long> delete(Long id) {
        skuFullReductionService.removeById(id);
        return BaseResult.success(id);
    }
}

